import osUsage from '@znode/os-usage'
import fs from 'fs';
import ping from 'ping'


export default async() => {
  const usage = await osUsage() // 获取cpu使用率 内存 硬盘等使用信息
  const { cpu, memory, disk } = usage

  // 获取公网ip
  const { numeric_host } = await ping.promise.probe('sslink.top') // 如果ping不通则返回am字符串
  
  // 获取树莓派CPU温度
  const result = parseInt(fs.readFileSync('/sys/class/thermal/thermal_zone0/temp', 'utf8'))
  const temp = Math.round(result / 1000)

  return {cpu, memory, disk, temp, ip: numeric_host === 'am'? '192.168.0.100' : numeric_host } 
}
